package com.ops.memcache.Servlet;


import com.ops.memcache.MemCache;
import com.ops.memcache.bean.MemCacheBean;
import com.ops.uitl.data.DataMap;
import com.ops.uitl.data.DatasetList;
import com.ops.uitl.data.IDataset;
import com.ops.uitl.tapestry.PageData;
import org.apache.log4j.Logger;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

public class InitMemcacheServlet extends HttpServlet implements ServletContextListener {
  private static final long serialVersionUID = 4719164013116871535L;
  protected static Logger log = Logger.getLogger(InitMemcacheServlet.class);

  public InitMemcacheServlet() {
  }

  public void init() throws ServletException {
    super.init();
    log.info("Loading Memcache ......");
    MemCacheBean bean = new MemCacheBean();
    new DatasetList();

    try {
      IDataset dataset = bean.query_MemcacheInfo_bean(new PageData(), new DataMap(), MemCache.get_chan_id());
      log.info("memcache_Set starting........");
      MemCache.memcache_Set(dataset);
      log.info("memcache_Print starting........");
      log.info("memcache_Print:" + MemCache.memcache_Print());
    } catch (Exception var4) {
      log.error("查数据库出错！请检查配置，Memcache当前不可用....");
      var4.printStackTrace();
    }

  }

  public void contextInitialized(ServletContextEvent arg0) {
  }

  public void contextDestroyed(ServletContextEvent sce) {
  }
}
